<?php

/**
 * 应用程序 - 控制器类
 * 
 * @package    01CMS
 * @subpackage admin
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

class AppController extends Controller
{
    public $title = '应用程序';
    public $Db;

    function __construct ()
    {
        parent::__construct();
        if (! model('User')->isLogined())
        {
            redirect('admin/login?url=' . getCurUrl());
        }
        if (! model('User')->checkAuth())
        {
            exit('您的权限不足');
        }
        $this->Db = model('Db');
    }

    function ad ($action = '', $id = 0)
    {
        if ($action == 'update' || $action == 'insert')
        {
            $data = $this->Load->post('name,exp,startTime,endTime,code|广告内容不能为空,expContent|内容不能为空');
            if ($error = $this->Load->getError())
            {
                response($error);
            }
            $data['startTime'] = strtotime($data['startTime']);
            $data['endTime'] = strtotime($data['endTime']);
            $this->data = $data;
        }
        else if($action == 'lists')
        {
            $where = '1';
            $queryVars = $this->Load->query('id,name');
            if ($queryVars)
            {
                $this->keyWord = slashQuotes($queryVars, 'strip');
                $where = empty($queryVars['id']) ? $where : $where . " AND id='{$queryVars['id']}'";
                $where = empty($queryVars['name']) ? $where : $where . " AND name like '%{$queryVars['name']}%'";
            }
            $this->where = $where;
        }
        $this->title = $this->title . ' => 广告管理';
        $this->id = $id;
        $this->order = 'id desc';
        $this->action($action);
    }
}
